package com.softserveinc.ita.kaiji.model.player.bot;

import com.softserveinc.ita.kaiji.model.Card;
import com.softserveinc.ita.kaiji.model.player.AbstractPlayer;
import com.softserveinc.ita.kaiji.model.game.GameHistory;

/**
 * @author  Ievgen Sukhov
 * @since 19.03.14.
 * @version 2.1
 */
public abstract class Bot extends AbstractPlayer {

    protected Types type;
    protected GameHistory gameData;

    /**
     * Executes specified strategy for different types of bots
     * @throws java.lang.IllegalStateException if no GameHistory is available
     */
    protected abstract void executeStrategy();

    @Override
    public Boolean isBot() {
        return true;
    }

    public Types getType() {
        return type;
    }

    public void setType(Types type) {
        this.type = type;
    }

    /**
     * Set <code>GameHistory</code> instance from current game
     * Relevant for some strategies
     * @param gameData - <code>GameHistory</code> object that stores statistics from game
     */
    public void setGameData(GameHistory gameData) {
        this.gameData = gameData;
    }

    public GameHistory getGameData() {
       return this.gameData;
    }

    /**
     *
     * @param card needed only for testing purposes,
     * <code>null</code> is desirable so bot can choose card
     */
    @Override
    public void makeTurn(Card card) {
        logger.info("Making turn for " + type + " bot");
        if (statusChanger.getCurrentState()==PlayerStatus.TURN_READY){

        if (card == null) {
                       executeStrategy();
                       statusChanger.switchState(PlayerStatus.TURN_FINISHED);
        } else if (this.deck.pickCard(card)) {
                        this.chosenCard = card;
                        statusChanger.switchState(PlayerStatus.TURN_FINISHED);
                    } else {
                        this.chosenCard = null;
                        statusChanger.switchState(PlayerStatus.PLAYER_BROKEN);
                        throw new IllegalArgumentException("No such card in the deck!");
                    }

            } else {
            statusChanger.switchState(PlayerStatus.PLAYER_BROKEN);
            throw new IllegalStateException("Can not make turn, wrong state!");
        }
        }

    public static enum Types {
        EASY, MEDIUM, HARD;
    }
}




